#include <cstdio>

const int N = 1000005, mod = 1e8 + 7;
int n, t;
int e_cnt, heads[N], f[N], g[N];

struct Edge {
  int v, nxt;
} e[N << 1];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
  e[++e_cnt].v = u, e[e_cnt].nxt = heads[v], heads[v] = e_cnt;
}

void solve(int u, int fa) {
  for (int i = heads[u], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != fa) {
      solve(v, u);
      f[u] = 1ll * f[v] * (g[u] + 1) % mod + 1ll * f[u] * (g[v] + 1) % mod, f[u] %= mod;
      g[u] = g[u] + 1ll * (g[u] + 1) * g[v] % mod, g[u] %= mod;
    }
  }
  f[u] += t ? u : 1, f[u] %= mod, ++g[u];
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P5007 DDOSvoid 的疑惑.in", "r", stdin);
  freopen("P5007 DDOSvoid 的疑惑.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &t);
  for (int i = 1, u, v; i < n; ++i) {
    scanf("%d%d", &u, &v);
    add(u, v);
  }
  solve(1, 1);
  printf("%d", f[1]);
  return 0;
}